<?php

/**
 * login actions.
 *
 * @package    sf.mismanage.com
 * @subpackage login
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2692 2006-11-15 21:03:55Z fabien $
 */
class loginActions extends sfActions
{
    /**
     * Executes index action
     *
     */
    public function executeIndex()
    {
        $this->mailaddress = $this->getRequestParameter('mailaddress');
        return sfView::SUCCESS;
    }

    public function executeSubmit()
    {
        $this->mailaddress = $this->getRequestParameter("mailaddress");
        $this->password = $this->getRequestParameter("password");

        if($this->mailaddress !="" && $this->password != "")
        {
            $c = new Criteria;
            $c->add(MemberPeer::MAILADDRESS, $this->mailaddress);
            $c->add(MemberPeer::PASSWORD, $this->password);
            $member = MemberPeer::doSelectOne($c);

            if($member)
            {
                $this->getUser()->setAttribute("member_id", $member->getId(),sfConfig::get("sf_session_name"));
                $this->getUser()->setAttribute("username", $member->getUsername(),sfConfig::get("sf_session_name"));
                $this->getUser()->setAttribute("admin_yn", $member->getAdminYn(),sfConfig::get("sf_session_name"));
                $this->redirect("/");
            }
        }
        $this->redirect("/login");
    }

    public function handleErrorSubmit()
    {
        $this->request->setParameter("mailaddress",$this->getRequestParameter("mailaddress"));
        $this->forward("login", "index");
    }
}
